//
//  SelectGoodsCell.m
//  YiBaoStore
//
//  Created by 毛云河 on 2019/1/5.
//  Copyright © 2019 小河. All rights reserved.
//

#import "SelectGoodsCell.h"

@implementation SelectGoodsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createView];
    }
    
    return self;
}

- (void)createView
{
    self.backgroundColor = [UIColor whiteColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 1)];
    [self.contentView addSubview:lineView];
    lineView.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    
    self.mainIconImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.mainIconImage];
    self.mainIconImage.backgroundColor = [UIColor lightGrayColor];
    self.mainIconImage.contentMode = UIViewContentModeScaleAspectFill;
    self.mainIconImage.clipsToBounds = YES;
    
    self.ziCaiLabel = [[UILabel alloc] init];
    [self.mainIconImage addSubview:self.ziCaiLabel];
    self.ziCaiLabel.backgroundColor = RGBACOLOR(239, 208, 83, 0.9);
    self.ziCaiLabel.font = FontWithSize(12);
    self.ziCaiLabel.textColor = [UIColor whiteColor];
    self.ziCaiLabel.textAlignment = 1;
    self.ziCaiLabel.text = @"自采";
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.textAlignment = 0;
    self.titleLabel.textColor = BlackTextColor;
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = FontWithSize(14);
    
    self.codeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.codeLabel];
    self.codeLabel.textAlignment = 0;
    self.codeLabel.textColor = RGBACOLOR(194, 194, 194, 1);
    self.codeLabel.font = FontWithSize(12);
    
    self.priceLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.priceLabel];
    self.priceLabel.textAlignment = 0;
    self.priceLabel.textColor = BlackTextColor;
    self.priceLabel.font = FontWithSize(14);
    
    self.settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.settingBtn];
    self.settingBtn.titleLabel.font = FontWithSize(12);
    [self.settingBtn setTitle:@"设置活动" forState:UIControlStateNormal];
    [self.settingBtn setTitleColor:RGBACOLOR(2, 2, 0, 1) forState:UIControlStateNormal];
    self.settingBtn.layer.cornerRadius = 15;
    self.settingBtn.layer.masksToBounds = YES;
    self.settingBtn.backgroundColor = BtnBgColor;
}

- (void)layoutSubviews
{
    self.mainIconImage.frame = CGRectMake(15, 15, 100, 100);
    self.titleLabel.frame = CGRectMake(self.mainIconImage.right+10, 15, SCREENWIDTH-self.mainIconImage.right-10-15, 44);
    self.ziCaiLabel.frame = CGRectMake(0, self.mainIconImage.height-30, self.mainIconImage.width, 30);
    self.codeLabel.frame = CGRectMake(self.mainIconImage.right+10, self.titleLabel.bottom+5, 100, 12);
    [self.codeLabel sizeToFit];
    self.priceLabel.frame = CGRectMake(self.mainIconImage.right+10, self.codeLabel.bottom+18, 120, 14);
    [self.priceLabel sizeToFit];
    self.settingBtn.frame = CGRectMake(SCREENWIDTH-70-15, self.titleLabel.bottom+26, 70, 30);
}

- (void)setCellWithMode:(MainModel *)model
{
    [self.mainIconImage sd_setImageWithURL:[NSURL URLWithString:model.showImage] placeholderImage:[UIImage imageNamed:@"zhanwei100"]];
    self.titleLabel.text = [NSString stringWithFormat:@"%@",model.title];
    self.codeLabel.text = [NSString stringWithFormat:@"条码 %@",model.barcode];
    float price = [model.price floatValue];
    self.priceLabel.text = [NSString stringWithFormat:@"￥%0.2f",price];
    
}

@end
